package org.jeecg.modules.yw.service;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.jeecg.modules.yw.entity.EnterPrise;
import org.jeecg.modules.yw.entity.Order;
import org.jeecg.modules.yw.mapper.EnterPriseMapper;
import org.jeecg.modules.yw.mapper.OrderMapper;
import org.jeecg.modules.yw.utils.DateUtils;
import org.jeecg.modules.yw.vo.EnterPriseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@Service
public class EnterPriseService extends ServiceImpl<EnterPriseMapper, EnterPrise> {
    @Autowired
    private EnterPriseMapper enterPriseMapper;
    
    @Autowired
    private OrderMapper orderMapper;

    public EnterPrise login(String mobile, String password) {
            return enterPriseMapper.login(mobile, password);
        }

    public IPage<EnterPriseVo> pageEnter(Page<EnterPrise> page, LambdaQueryWrapper<EnterPrise> queryWrapper) {
        return enterPriseMapper.pageEnter(page, queryWrapper);
    }
    
    public String getPaswordByMobile(String mobile) {
        return enterPriseMapper.getPasswordByMobile(mobile);
    }
    
    
    public String getIdByMobile(String mobile) {
        return enterPriseMapper.getIdByMobile(mobile);
    }
    public List<EnterPrise> pageEnter(int roleId,String[] areas, String orderId) {
    	Order order = orderMapper.getOrder(orderId);
    	String date  = DateUtils.getDateStr();
    	if(roleId == 1) {
    		return enterPriseMapper.selectMcqy(date,areas, null,null);
    	}
    	else if (roleId == 2) {
        	return enterPriseMapper.selectZzList(order.getYyTime().substring(0,10),areas, null,null);
        } 
    	String djTime = order.getDjTime();    
    	if (StringUtils.isNotBlank(djTime)) {
    		djTime = djTime.substring(0,10);
    	} else {
    		djTime = order.getYyTime().substring(0,10);
    	}
        return enterPriseMapper.selectDjshList(djTime,areas, null,null);
    }
    
    
    public List<EnterPrise> pageEnter1(String orderId, int roleId,String[] areas,String provinceCode,String cityCode) {
    	Order order = orderMapper.getOrder(orderId);
    	String date  = DateUtils.getDateStr();
    	if(roleId == 1) {
    		return enterPriseMapper.selectMcqy(date,areas,provinceCode,cityCode);
    	}
    	else if (roleId == 2) {
        	return enterPriseMapper.selectZzList(order.getYyTime().substring(0,10),areas,provinceCode,cityCode);
        } 
    	String djTime = order.getDjTime();    
    	if (StringUtils.isNotBlank(djTime)) {
    		djTime = djTime.substring(0,10);
    	}  else {
    		djTime = order.getYyTime().substring(0,10);
    	}
        return enterPriseMapper.selectDjshList(djTime,areas,provinceCode,cityCode);
    }
}

